home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 10 / AACD 10.iso / AACD / Games / MAME / src / machine / nitedrvr.c < prev    next >
C/C++ Source or Header  |  2000-04-04  |  6KB  |  250 lines

  1. /***************************************************************************
  2.  
  3. Atari Night Driver machine
  4.  
  5. If you have any questions about how this driver works, don't hesitate to
  6. ask.  - Mike Balfour (mab22@po.cwru.edu)
  7. ***************************************************************************/
  8.  
  9. #include "driver.h"
  10. #include "vidhrdw/generic.h"
  11.  
  12. unsigned char *nitedrvr_ram;
  13.  
  14. int nitedrvr_gear = 1;
  15. int nitedrvr_track = 0;
  16.  
  17. static int nitedrvr_steering_buf = 0;
  18. static int nitedrvr_steering_val = 0x00;
  19.  
  20. /***************************************************************************
  21. nitedrvr_ram_r
  22. ***************************************************************************/
  23. READ_HANDLER( nitedrvr_ram_r )
  24. {
  25.     return nitedrvr_ram[offset];
  26. }
  27.  
  28. /***************************************************************************
  29. nitedrvr_ram_w
  30. ***************************************************************************/
  31. WRITE_HANDLER( nitedrvr_ram_w )
  32. {
  33.     nitedrvr_ram[offset]=data;
  34. }
  35.  
  36. /***************************************************************************
  37. Steering
  38.  
  39. When D7 is high, the steering wheel has moved.
  40. If D6 is low, it moved left.  If D6 is high, it moved right.
  41. Be sure to keep returning a direction until steering_reset is called,
  42. because D6 and D7 are apparently checked at different times, and a
  43. change in-between can affect the direction you move.
  44. ***************************************************************************/
  45. static int nitedrvr_steering(void)
  46. {
  47.     static int last_val=0;
  48.     int this_val;
  49.     int delta;
  50.  
  51.     this_val=input_port_5_r(0);
  52.  
  53.     delta=this_val-last_val;
  54.     last_val=this_val;
  55.     if (delta>128) delta-=256;
  56.     else if (delta<-128) delta+=256;
  57.     /* Divide by four to make our steering less sensitive */
  58.     nitedrvr_steering_buf+=(delta/4);
  59.  
  60.     if (nitedrvr_steering_buf>0)
  61.     {
  62.         nitedrvr_steering_buf--;
  63.         nitedrvr_steering_val=0xC0;
  64.     }
  65.     else if (nitedrvr_steering_buf<0)
  66.     {
  67.         nitedrvr_steering_buf++;
  68.         nitedrvr_steering_val=0x80;
  69.     }
  70.     else
  71.     {
  72.         nitedrvr_steering_val=0x00;
  73.     }
  74.  
  75.     return nitedrvr_steering_val;
  76. }
  77.  
  78. /***************************************************************************
  79. nitedrvr_steering_reset
  80. ***************************************************************************/
  81. READ_HANDLER( nitedrvr_steering_reset_r )
  82. {
  83.     nitedrvr_steering_val=0x00;
  84.     return 0;
  85. }
  86.  
  87. WRITE_HANDLER( nitedrvr_steering_reset_w )
  88. {
  89.     nitedrvr_steering_val=0x00;
  90. }
  91.  
  92.  
  93. /***************************************************************************
  94. nitedrvr_in0_r
  95.  
  96. Night Driver looks for the following:
  97.     A: $00
  98.         D4 - OPT1
  99.         D5 - OPT2
  100.         D6 - OPT3
  101.         D7 - OPT4
  102.     A: $01
  103.         D4 - TRACK SET
  104.         D5 - BONUS TIME ALLOWED
  105.         D6 - VBLANK
  106.         D7 - !TEST
  107.     A: $02
  108.         D4 - !GEAR 1
  109.         D5 - !GEAR 2
  110.         D6 - !GEAR 3
  111.         D7 - SPARE
  112.     A: $03
  113.         D4 - SPARE
  114.         D5 - DIFFICULT BONUS
  115.         D6 - STEER A
  116.         D7 - STEER B
  117.  
  118. Fill in the steering and gear bits in a special way.
  119. ***************************************************************************/
  120.  
  121. READ_HANDLER( nitedrvr_in0_r )
  122. {
  123.     int gear;
  124.  
  125.     gear=input_port_2_r(0);
  126.     if (gear & 0x10)                nitedrvr_gear=1;
  127.     else if (gear & 0x20)            nitedrvr_gear=2;
  128.     else if (gear & 0x40)            nitedrvr_gear=3;
  129.     else if (gear & 0x80)            nitedrvr_gear=4;
  130.  
  131.     switch (offset & 0x03)
  132.     {
  133.         case 0x00:                        /* No remapping necessary */
  134.             return input_port_0_r(0);
  135.         case 0x01:                        /* No remapping necessary */
  136.             return input_port_1_r(0);
  137.         case 0x02:                        /* Remap our gear shift */
  138.             if (nitedrvr_gear==1)        return 0xE0;
  139.             else if (nitedrvr_gear==2)    return 0xD0;
  140.             else if (nitedrvr_gear==3)    return 0xB0;
  141.             else                        return 0x70;
  142.         case 0x03:                        /* Remap our steering */
  143.             return (input_port_3_r(0) | nitedrvr_steering());
  144.         default:
  145.             return 0xFF;
  146.     }
  147. }
  148.  
  149. /***************************************************************************
  150. nitedrvr_in1_r
  151.  
  152. Night Driver looks for the following:
  153.     A: $00
  154.         D6 - SPARE
  155.         D7 - COIN 1
  156.     A: $01
  157.         D6 - SPARE
  158.         D7 - COIN 2
  159.     A: $02
  160.         D6 - SPARE
  161.         D7 - !START
  162.     A: $03
  163.         D6 - SPARE
  164.         D7 - !ACC
  165.     A: $04
  166.         D6 - SPARE
  167.         D7 - EXPERT
  168.     A: $05
  169.         D6 - SPARE
  170.         D7 - NOVICE
  171.     A: $06
  172.         D6 - SPARE
  173.         D7 - Special Alternating Signal
  174.     A: $07
  175.         D6 - SPARE
  176.         D7 - Ground
  177.  
  178. Fill in the track difficulty switch and special signal in a special way.
  179. ***************************************************************************/
  180.  
  181. READ_HANDLER( nitedrvr_in1_r )
  182. {
  183.     static int ac_line=0x00;
  184.     int port;
  185.  
  186.     ac_line=(ac_line+1) % 3;
  187.  
  188.     port=input_port_4_r(0);
  189.     if (port & 0x10)                nitedrvr_track=0;
  190.     else if (port & 0x20)            nitedrvr_track=1;
  191.     else if (port & 0x40)            nitedrvr_track=2;
  192.  
  193.     switch (offset & 0x07)
  194.     {
  195.         case 0x00:
  196.             return ((port & 0x01) << 7);
  197.         case 0x01:
  198.             return ((port & 0x02) << 6);
  199.         case 0x02:
  200.             return ((port & 0x04) << 5);
  201.         case 0x03:
  202.             return ((port & 0x08) << 4);
  203.         case 0x04:
  204.             if (nitedrvr_track == 1) return 0x80; else return 0x00;
  205.         case 0x05:
  206.             if (nitedrvr_track == 0) return 0x80; else return 0x00;
  207.         case 0x06:
  208.             /* TODO: fix alternating signal? */
  209.             if (ac_line==0) return 0x80; else return 0x00;
  210.         case 0x07:
  211.             return 0x00;
  212.         default:
  213.             return 0xFF;
  214.     }
  215. }
  216.  
  217. /***************************************************************************
  218. nitedrvr_out0_w
  219.  
  220. Sound bits:
  221.  
  222. D0 = !SPEED1
  223. D1 = !SPEED2
  224. D2 = !SPEED3
  225. D3 = !SPEED4
  226. D4 = SKID1
  227. D5 = SKID2
  228. ***************************************************************************/
  229. WRITE_HANDLER( nitedrvr_out0_w )
  230. {
  231.     /* TODO: put sound bits here */
  232. }
  233.  
  234. /***************************************************************************
  235. nitedrvr_out1_w
  236.  
  237. D0 = !CRASH - also drives a video invert signal
  238. D1 = ATTRACT
  239. D2 = Spare (Not used)
  240. D3 = Not used?
  241. D4 = LED START
  242. D5 = Spare (Not used)
  243. ***************************************************************************/
  244. WRITE_HANDLER( nitedrvr_out1_w )
  245. {
  246.     osd_led_w(0,(data & 0x10)>>4);
  247.     /* TODO: put sound bits here */
  248. }
  249.  
  250.